<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::QueryMethods::WhereChain</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveRecord::QueryMethods::WhereChain 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activerecord/lib/active_record/relation/query_methods_rb.html">activerecord/lib/active_record/relation/query_methods.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="WhereChain.html">WhereChain</a> objects act as placeholder for
queries in which where does not have any parameter. In this case, where
must be chained with <a href="WhereChain.html#method-i-not">not</a> to
return a new relation.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="WhereChain.html#method-c-new">new</a>,
              </li>
            
              
              <li>
                <a href="WhereChain.html#method-i-not">not</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(scope)
            
            <a href="WhereChain.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/746a9992f0a842ded7a15cc5ce0afd0fa00f2ada/activerecord/lib/active_record/relation/query_methods.rb#L10" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/relation/query_methods.rb, line 10</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">scope</span>)
  <span class="ruby-ivar">@scope</span> = <span class="ruby-identifier">scope</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-not">
            
              <b>not</b>(opts, *rest)
            
            <a href="WhereChain.html#method-i-not" name="method-i-not" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a new relation expressing WHERE + NOT condition according to the
conditions in the arguments.</p>

<p><code>not</code> accepts conditions as a string, array, or hash. See where
for more details on each format.</p>

<pre>User.where.not(&quot;name = 'Jon'&quot;)
# SELECT * FROM users WHERE NOT (name = 'Jon')

User.where.not([&quot;name = ?&quot;, &quot;Jon&quot;])
# SELECT * FROM users WHERE NOT (name = 'Jon')

User.where.not(name: &quot;Jon&quot;)
# SELECT * FROM users WHERE name != 'Jon'

User.where.not(name: nil)
# SELECT * FROM users WHERE name IS NOT NULL

User.where.not(name: %w(Ko1 Nobu))
# SELECT * FROM users WHERE name NOT IN ('Ko1', 'Nobu')

User.where.not(name: &quot;Jon&quot;, role: &quot;admin&quot;)
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-not_source')" id="l_method-i-not_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/746a9992f0a842ded7a15cc5ce0afd0fa00f2ada/activerecord/lib/active_record/relation/query_methods.rb#L37" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-not_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/relation/query_methods.rb, line 37</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">not</span>(<span class="ruby-identifier">opts</span>, *<span class="ruby-identifier">rest</span>)
  <span class="ruby-identifier">where_value</span> = <span class="ruby-ivar">@scope</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:build_where</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">rest</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rel</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">rel</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">In</span>
      <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">NotIn</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rel</span>.<span class="ruby-identifier">left</span>, <span class="ruby-identifier">rel</span>.<span class="ruby-identifier">right</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">Equality</span>
      <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">NotEqual</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rel</span>.<span class="ruby-identifier">left</span>, <span class="ruby-identifier">rel</span>.<span class="ruby-identifier">right</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>
      <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">Not</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">SqlLiteral</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rel</span>))
    <span class="ruby-keyword">else</span>
      <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Nodes</span><span class="ruby-operator">::</span><span class="ruby-constant">Not</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rel</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@scope</span>.<span class="ruby-identifier">where_values</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">where_value</span>
  <span class="ruby-ivar">@scope</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    